home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MACSHELL / MS1 / COMMANDS / SETFILE.C < prev    next >
Text File  |  1992-12-02  |  8KB  |  332 lines

  1. /*
  2.  *    MacShell Source File
  3.  *
  4.  *    Copyright (c) 1989, 1990, 1991, 1992  Suick Bay Technologies.  All rights reserved.
  5.  *
  6.  *
  7.  *    RESTRICTIONS ON MacShell program and source code.
  8.  *
  9.  *    Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
  10.  *    restricted use by the owner of the CDROM "Disk to the future II".
  11.  *
  12.  *    Ñ╩No permission is granted for any commercial use without the written
  13.  *    consent of the Suick Bay Technologies.
  14.  *
  15.  *    Ñ╩No permission is granted for any redistribution of any kind use without
  16.  *    the written consent of the Suick Bay Technologies.
  17.  *
  18.  *    Ñ╩Permission is granted to use this for any personal noncommercial use.
  19.  *
  20.  *    Ñ╩You may not distribute source or executable code at all, nor may you 
  21.  *    distribute it with or within a commercial product without the written
  22.  *    consent of the Suick Bay Technologies.  Please send modifications to 
  23.  *    the author for inclusion in updates to the program.  Thanks.
  24.  *
  25.  *
  26.  *    MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  27.  *    WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  28.  *    PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  29.  *
  30.  *    SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  31.  *    INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
  32.  *    OR ANY PART THEREOF. 
  33.  *
  34.  *    In no event will Suick Bay Technologies be liable for any lost revenue
  35.  *    or profits or other special, indirect and consequential damages, even if
  36.  *    Suick Bay Technologies has been advised of the possibility of such damages.
  37.  *
  38.  *    Suick Bay Technologies can be reached at:
  39.  *    
  40.  *    8768 Cottonwood lane
  41.  *    Maple Grove, MN 55369
  42.  *    Voice: (612) 425-7025
  43.  *    AppleLink: D5233
  44.  *    
  45.  *
  46.  *    No parts of this software may be reproduced or stored in a
  47.  *    retrieval system or transmitted in any form, or any means,
  48.  *    electronic, mechanical, photocopying, recording or otherwise,
  49.  *    without the prior written permission of Suick Bay Technologies.
  50.  *    
  51.  *    Spread the word and not the disk.
  52.  *    
  53.  *    SPK 012290    :    Initial
  54.  */
  55.  
  56. #include    "SystemPub.h"
  57. #include    "Proc.h"
  58. #include    "ShellPub.h"
  59. #include    "Path.h"
  60.  
  61. /*******************************************************************
  62.  *
  63.  *    Function SetFile
  64.  *
  65.  *    PathName Callback function
  66.  *
  67.  *    usage SetFile [options] [names]    
  68.  *
  69.  *    L   Locked            = Bit 0 of ioFlAttrib    
  70.  *    V   Invisible        = Bit 14 of finder flags
  71.  *    B   Bundle            = Bit 13 of finder flags
  72.  *    S   System            = Bit 12 of finder flags
  73.  *    I   Inited            = Bit 8 of finder flags
  74.  *    D   Desktop            = Bit 0 of finder flags
  75.  *    M   Shared            = Bit 6 of finder flags
  76.  *    A   Always switch    = Bit 5 of finder flags
  77.  *
  78.  *    No INITS     =     Bit 7 of finder flags
  79.  *    BOZO         =     Bit 11 of finder flags
  80.  *    Changed        =    Bit 10 of finder flags
  81.  *
  82.  *******************************************************************/
  83.  
  84. #define        fLocked        1
  85. #define        fSystem        0x1000
  86. #define        fInited        0x0100
  87. #define        fShared        0x0040
  88. #define        fSwtLan        0x0020
  89. #define        fNoInit        0x0080
  90. #define        fBusy        0x0400
  91. #define        fChange        0x0200
  92.  
  93. int16        forceAttr,
  94.             attrLocked,
  95.             attrInvis,
  96.             attrBundle,
  97.             attrSystem,
  98.             attrInited,
  99.             attrDeskTop,
  100.             attrShared,
  101.             attrSwitch;
  102.  
  103.  
  104. #define        attrType        (**MyShell).Proc[ProcID].long0
  105. #define        attrCrea        (**MyShell).Proc[ProcID].long1
  106.  
  107. char        attrStr[ 32 ];
  108.  
  109. ScanAttrStr()
  110. {
  111. char    *cp = attrStr;
  112.     while( *cp )
  113.         {
  114.         switch( *cp )
  115.             {
  116.             case    'l'        :
  117.             case    'L'        :    attrLocked    = (*cp == 'L');     break;
  118.             case    'v'        :
  119.             case    'V'        :    attrInvis    = (*cp == 'V');     break;
  120.             case    'b'        :
  121.             case    'B'        :    attrBundle    = (*cp == 'B');     break;
  122.             case    's'        :
  123.             case    'S'        :    attrSystem    = (*cp == 'S');     break;
  124.             case    'i'        :
  125.             case    'I'        :    attrInited    = (*cp == 'I');     break;
  126.             case    'd'        :
  127.             case    'D'        :    attrDeskTop    = (*cp == 'D');     break;
  128.             case    'm'        :
  129.             case    'M'        :    attrShared    = (*cp == 'M');     break;
  130.             case    'a'        :
  131.             case    'A'        :    attrSwitch     = (*cp == 'A');     break;
  132.             }
  133.         cp++;
  134.         }
  135. }
  136.  
  137.  
  138. GetAttr( int16 fdrFlags, int16 ioFlAttrib )
  139. {
  140.     attrLocked    =    (ioFlAttrib & fLocked);
  141.     attrInvis    =    (fdrFlags & fInvisible);
  142.     attrBundle    =    (fdrFlags & fHasBundle);
  143.     attrSystem    =    (fdrFlags & fSystem);
  144.     attrInited    =    (fdrFlags & fInited);
  145.     attrDeskTop    =    (fdrFlags & fOnDesk);
  146.     attrShared    =    (fdrFlags & fShared);
  147.     attrSwitch    =    (fdrFlags & fSwtLan);
  148. }
  149.  
  150. DoBit( int16 *iptr, int16 bit, int16 on )
  151. {
  152. int16        val = *iptr, mask;
  153.  
  154.     mask = 0x0001 << bit;
  155.     
  156.     if( on )
  157.         *iptr |= mask;
  158.     else
  159.         *iptr &= (mask ^ 0xFFFF);
  160. }
  161.  
  162. SetAttr(  FInfo *ioFlFndrInfo, OsType SAattrType, OsType SAattrCrea )
  163. {
  164.     DoBit( &(ioFlFndrInfo->fdFlags), 14, attrInvis );
  165.     DoBit( &(ioFlFndrInfo->fdFlags), 13, attrBundle );
  166.     DoBit( &(ioFlFndrInfo->fdFlags), 12, attrSystem );
  167.     DoBit( &(ioFlFndrInfo->fdFlags),  8, attrInited );
  168.     DoBit( &(ioFlFndrInfo->fdFlags),  0, attrDeskTop );
  169.     DoBit( &(ioFlFndrInfo->fdFlags),  6, attrShared );
  170.     DoBit( &(ioFlFndrInfo->fdFlags),  5, attrSwitch );
  171.     
  172.     if( SAattrType )
  173.         ioFlFndrInfo->fdType = SAattrType;
  174.         
  175.     if( SAattrCrea )
  176.         ioFlFndrInfo->fdCreator = SAattrCrea;
  177. }
  178.  
  179.  
  180. void        SetFileCallBack( WHandle ShellWh, int16 ProcID,
  181.                 char *path, char *last,
  182.                 pathType what, int16 vRefNum, int32 dirID )
  183. {
  184. HFileInfo    pb;
  185. OSErr        err;
  186. char        str[ 256 ];
  187. ShellWindRec    **MyShell = (ShellWindRec **) (**ShellWh).thing;
  188.  
  189.     if( what == pathIsFile )
  190.         {
  191.         strcpy( str, last );
  192.         CtoPstr( str );
  193.         
  194.         pb.ioCompletion = NULL;
  195.         pb.ioNamePtr     = (StringPtr) str;
  196.         pb.ioVRefNum    = vRefNum;
  197.         pb.ioFDirIndex    = 0;
  198.         pb.ioDirID        = dirID;
  199.         
  200.         err = PBHGetFInfo( &pb, FALSE );
  201.         if( err )
  202.             {
  203.             procPrintf( ShellWh, ProcID, "setfile : can't get info for %s (%d)\n",
  204.                 last, err );
  205.             return;
  206.             }
  207.         
  208.         GetAttr( pb.ioFlFndrInfo.fdFlags, pb.ioFlAttrib );
  209.         
  210.         if( forceAttr )
  211.             ScanAttrStr();
  212.  
  213.         SetAttr( (FInfo *) &(pb.ioFlFndrInfo), attrType, attrCrea );
  214.             
  215.         if( forceAttr && attrLocked )
  216.             err = HSetFLock( vRefNum, dirID, str );
  217.         else if( forceAttr && !attrLocked )
  218.             err = HRstFLock( vRefNum, dirID, str );
  219.  
  220.         if( !err )
  221.             err = HSetFInfo( vRefNum, dirID, str, (FInfo *) &(pb.ioFlFndrInfo) );
  222.             
  223.         if( err )
  224.             {
  225.             procPrintf( ShellWh, ProcID, "setfile : can't set info for %ps (%d)\n",
  226.                 str, err );
  227.             return;
  228.             }
  229.         }
  230. }
  231.  
  232. void        SetFileAttr( WHandle ShellWh, int16 ProcID, char *argument )
  233. {
  234. ShellWindRec    **MyShell;
  235.  
  236.     MyShell = (ShellWindRec **) (**ShellWh).thing;
  237.  
  238.     ExpandPath( ShellWh, ProcID, argument, (ProcPtr) SetFileCallBack,
  239.             (**MyShell).pwdVRefNum, (**MyShell).pwdDirID );
  240.  
  241.     ResetShellPWD( ShellWh );
  242. }
  243.  
  244. /*******************************************************************/
  245.  
  246. Boolean            DoSETFILE( int16 ProcToken, WHandle ShellWh, int16 ProcID,
  247.                     char *string )
  248. {
  249. int16            i, argc;
  250. char            *cp, argument[ 256 ];
  251. ShellWindRec    **MyShell = (ShellWindRec **) (**ShellWh).thing;
  252.  
  253.     switch( ProcToken )
  254.         {
  255.         case    PROC_INIT    :
  256.             (**MyShell).Proc[ ProcID ].flags = TRUE;
  257.             break;
  258.             
  259.         case    PROC_TERM    :
  260.         case    PROC_BREAK    :
  261.             /* Tell the shell that we're done */
  262.             SendOutToken( ShellWh, ProcID, PROC_BREAK );
  263.             /* Turn ourself off */
  264.             (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  265.             break;
  266.             
  267.         case    PROC_STDIN    :
  268.             if( (**MyShell).Proc[ ProcID ].flags )
  269.                 {
  270.                 (**MyShell).Proc[ ProcID ].flags = FALSE;        
  271.  
  272.                 /* get arguments */
  273.                 argc = (**MyShell).Proc[ ProcID ].argc;
  274.                 forceAttr = FALSE;
  275.                 attrType = 0L;
  276.                 attrCrea = 0L;
  277.                 
  278.                 for( i = 1; i < argc; i++ )
  279.                     {
  280.                     GetArgv( ShellWh, ProcID, i, argument );
  281.                     cp = argument;
  282.                     
  283.                     if( *cp++ == '-' )
  284.                         while( *cp )
  285.                             switch( *cp++ )
  286.                                 {
  287.                                 case    'a'    :    /* Attributes */
  288.                                     GetArgv( ShellWh, ProcID, ++i, attrStr );
  289.                                     forceAttr = TRUE;
  290.                                     break;
  291.                                                                         
  292.                                 case    't'    :        /* Type */
  293.                                     i++;
  294.                                     if( i < argc )
  295.                                         {
  296.                                         char    temp[ 256 ];
  297.                                         GetArgv( ShellWh, ProcID, i, temp );
  298.                                         attrType = StrToType( temp );
  299.                                         }
  300.                                     break;
  301.                                     
  302.                                 case    'c'    :        /* Creator */
  303.                                     i++;
  304.                                     if( i < argc )
  305.                                         {
  306.                                         char    temp[ 256 ];
  307.                                         GetArgv( ShellWh, ProcID, i, temp );
  308.                                         attrCrea = StrToType( temp );
  309.                                         }
  310.                                     break;
  311.                                 }
  312.                     }
  313.  
  314.                 for( i = 1; i < (**MyShell).Proc[ ProcID ].argc; i++ )
  315.                     {
  316.                     GetArgv( ShellWh, ProcID, i, argument );
  317.                     if( *argument == '-' )
  318.                         i++;
  319.                     else
  320.                         SetFileAttr( ShellWh, ProcID, argument );
  321.                     }
  322.  
  323.                 /* Tell the shell that we're done */
  324.                 SendOutToken(  ShellWh, ProcID, PROC_BREAK );
  325.                 
  326.                 /* Turn ourself off */
  327.                 (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  328.                 return( FALSE );
  329.                 }
  330.         }
  331. }
  332.